package com.scsj.supermarket.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.scsj.supermarket.R;

import java.util.List;
import java.util.Map;

/**
 * 商品浏览记录
 */

public class BrowsingHistoryAdapter extends BaseQuickAdapter<Map<String,String>, BaseViewHolder> {

    private Context mContext;
    private List data;
    private Boolean isEdit = false;
    public BrowsingHistoryAdapter(Context mContext) {
        super(R.layout.item_browsing_history);
        this.mContext = mContext;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final Map<String,String> item) {

        if(TextUtils.isEmpty(item.get("date"))){
            helper.getView(R.id.date_ll).setVisibility(View.GONE);
        }else {
            helper.getView(R.id.date_ll).setVisibility(View.VISIBLE);
            helper.setText(R.id.date_tv, item.get("date"));
        }

        TextView name_tv =  helper.getView(R.id.name_tv);//商品名
        LinearLayout price_ll =  helper.getView(R.id.price_ll);//价格
        TextView price_symbol_tv =  helper.getView(R.id.price_symbol_tv);//￥
        TextView price_integer_tv =  helper.getView(R.id.price_integer_tv);//元
        TextView price_decimals_tv =  helper.getView(R.id.price_decimals_tv);//角
        TextView price_null_tv =  helper.getView(R.id.price_null_tv);//无报价

        TextView similarity_tv =  helper.getView(R.id.similarity_tv);//看相似
        ImageView add_cart_iv =  helper.getView(R.id.add_cart_iv);//加入购物车

        ImageView title_select_iv =  helper.getView(R.id.title_select_iv);//选中状态（标题占位）
        ImageView select_iv =  helper.getView(R.id.select_iv);//选中状态

        if (item.get("type").equals("0")){//正常
            add_cart_iv.setVisibility(View.VISIBLE);
            helper.getView(R.id.out_of_stock_iv).setVisibility(View.GONE);
            helper.getView(R.id.sold_out_iv).setVisibility(View.GONE);

            name_tv.setTextColor(mContext.getResources().getColor(R.color.main_black_text));
            price_ll.setVisibility(View.VISIBLE);
            price_null_tv.setVisibility(View.GONE);

            price_symbol_tv.setTextColor(mContext.getResources().getColor(R.color.red));
            price_integer_tv.setTextColor(mContext.getResources().getColor(R.color.red));
            price_decimals_tv.setTextColor(mContext.getResources().getColor(R.color.red));

        }else  if (item.get("type").equals("1")){//无货
            add_cart_iv.setVisibility(View.GONE);
            helper.getView(R.id.out_of_stock_iv).setVisibility(View.VISIBLE);
            helper.getView(R.id.sold_out_iv).setVisibility(View.GONE);

            name_tv.setTextColor(mContext.getResources().getColor(R.color.default_text_color));
            price_ll.setVisibility(View.VISIBLE);
            price_null_tv.setVisibility(View.GONE);

            price_symbol_tv.setTextColor(mContext.getResources().getColor(R.color.default_text_color));
            price_integer_tv.setTextColor(mContext.getResources().getColor(R.color.default_text_color));
            price_decimals_tv.setTextColor(mContext.getResources().getColor(R.color.default_text_color));
        }else if (item.get("type").equals("2")){//下架
            add_cart_iv.setVisibility(View.GONE);
            helper.getView(R.id.out_of_stock_iv).setVisibility(View.GONE);
            helper.getView(R.id.sold_out_iv).setVisibility(View.VISIBLE);

            name_tv.setTextColor(mContext.getResources().getColor(R.color.notice_text_color));
            price_ll.setVisibility(View.GONE);
            price_null_tv.setVisibility(View.VISIBLE);
        }

        if(isEdit){
            helper.getView(R.id.add_cart_iv).setVisibility(View.GONE);
            similarity_tv.setVisibility(View.GONE);

            title_select_iv.setVisibility(View.INVISIBLE);
            select_iv.setVisibility(View.VISIBLE);

            if(item.get("isSelectd").equals("1")){
                select_iv.setImageResource(R.mipmap.cart_selected);
            }else {
                select_iv.setImageResource(R.mipmap.cart_unselected);
            }
        }else {
            helper.getView(R.id.add_cart_iv).setVisibility(View.VISIBLE);
            similarity_tv.setVisibility(View.VISIBLE);

            title_select_iv.setVisibility(View.GONE);
            select_iv.setVisibility(View.GONE);
        }
    }
    public void setEdit(Boolean b){
        this.isEdit = b;
        notifyDataSetChanged();
    }
}
